let parm1;
parm1 =localStorage.getItem('username');
if(parm1 != null){
    document.getElementById("id").innerHTML = "welcome,"+parm1
}

function out(){
    localStorage.removeItem("username")
}
// 登陆注册跳转
function login(){
    location.href="../glt/图书管理系统-登录注册.html"

}
function register(){
    location.href="../glt/图书管理系统-登录注册.html"
}

// 搜索按钮
function search(){
    let obj=document.getElementById("category");
    let Value = document.getElementById("search").value
    // console.log(obj.value)
    let str = Value.replace(/(^\s*)|(\s*$)/g, '');//去除空格;
 
    if (str == '' || str == undefined || str == null) {
        //return true;
        console.log('空')
        // alert("no!")
        location.href="./index.html"
    } else {
        //return false;
        console.log('非空');
        let searchType = localStorage.setItem('searchType', obj.value );
        let searchValue = localStorage.setItem('searchValue', Value);
        location.href="../zgq/search.html"

    }

    // if(searchValue = ''){
    //     alert("no!")
    //     location.href="./index.html"
    // }else{
    //     let searchType = localStorage.setItem('searchType', obj.value );
    //     let searchValue = localStorage.setItem('searchValue', Value);
    //     // location.href="../zgq/search.html"
    // }
    

    
    
    // console.log(localStorage.getItem('searchValue'))
    
}
function allbook(){
    let searchType = localStorage.setItem('searchType', 'allBook');
    let searchValue = localStorage.setItem('searchValue', '000');
    location.href="../zgq/search.html"
}

// 写整合好的文件里面需要跳转到的位置

// -------------------------------------------------------------------------------------axios
// 还书
// 假设我知道username
// let username = 'a'

// axios.defaults.baseURL= "http://y5mvy9.natappfree.cc/"
// 历史记录
axios.post("http://hvszny.natappfree.cc/test/getrecord",{
    username:"zhangshuai2021005731"
}).then(function(resposne){
    console.log(resposne.data)
    let res = resposne.data
    let outer = document.getElementById("history")
    let buf = ''
    for (let i = 0; i < res.length; i++) {
        buf += `
        <div class="item">
            <div>
            <span>${res[i].username} 于 </span><span>${res[i].borrow_date} 到 </span><span>${res[i].return_time} 阅读了《 ${res[i].bookname} 》</span>
            </div>
        </div>
           `
    }
    outer.innerHTML = buf
    
},function(error){
    // alert(error)
    console.log(error)
})

// 还书
function huan(){
    axios.post(
        "http://hvszny.natappfree.cc/test/sendreturnapplication",{
        username:"zhangshuai2021005731",
        bookid:'1'
    }).then(function(resposne){
        console.log(resposne.data)
        alert("还书成功！")
    },function(error){
        // alert(error)
    })
}


// 信息
axios.post("http://fnree5.natappfree.cc/AssetManagement_war_exploded/FeedbackServlet",{
    username:"zhangshuai"
}).then(function(resposne){
    console.log(resposne.data)
    // alert("收到信息！")
    document.getElementById("mes").innerHTML = resposne.data
},function(error){
    // alert(error)
})



// 返回顶部的按钮
$('.toTop').click(()=>{
    window.scrollTo(0,0);
  })
// -------------------------------------------------------------------------nav的hover效果
let yj=document.getElementsByClassName('li');
		for(let i=0;i<yj.length;i++){
			yj[i].onmouseover=function(){
			//console.log(i)
			this.style.backgroundColor="#e1eff8"
			this.style.color="#2c3c55"

		    }
            yj[i].onmouseout=function(){
                this.style.backgroundColor="";
                this.style.color="#fff";
            }
		}
// ------------------------------------------锚点滑动跳转

$(function(){
    $('a[href*=#],area[href*=#]').click(function() {
        console.log(this.pathname)
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
            let $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
            if ($target.length) {
                let targetOffset = $target.offset().top;
                $('html,body').animate({
                            scrollTop: targetOffset
                        },
                        0);
                        // 如果不写零 就太慢了！
                return false;
            }
        }
    });
})
// 轮播图
let left = document.querySelector(".button-left")
let right = document.querySelector(".button-right")
let min = document.querySelectorAll(".min")
let hotimgs = document.querySelector(".hot-imgs")

let time;
let index=0;
// 功能
function position(){
    hotimgs.style.left = (index * (-100)) + "%"
}
function add(){
    if(index >= min.length-1){
        index = 0
    }
    else{
        index++
    }
}
function back(){
    if(index < 1){
        index = min.length-1
    }
    else{
        index--
    }
}
// lunbo
function timer(){
    time = setInterval(()=>{
        index++
        if(index > min.length-1){
            index = 0
        }
        add()
        back()
        position()
    },2000)
}

for(let i =0;i<min.length;i++){
    min[i].addEventListener("click",()=>{
        index = i
        position()
        clearInterval(time)
        timer()
    })
}
// 开始轮播
timer()
// 左右按钮
left.addEventListener('click',()=>{
    back()

    position()
    clearInterval(time)
    timer()
})
right.addEventListener('click',()=>{
    add()

    position()
    clearInterval(time)
    timer()
})

// 已读按钮 变灰
// function read(){
//     console.log()
//     document.getElementById("btn-read").onclick = "return false;";
//     document.getElementById("btn-read").style.backgroundColor = "gray";
//     document.getElementById("btn-read").style.cursor = "default";
//     document.getElementById("commitbtn").setAttribute("disabled", true);
// }

